﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyDomainClustering
{
    class MyFusion : HAC.Fusion
    {
        /*
         * Given two clusters, calculate their distance by selecting the minimum distance bwteen their elements.
         * */
        public override float CalculateDistance(HAC.Cluster cluster1, HAC.Cluster cluster2)
        {
            float leastDistance = float.MaxValue;
            foreach (HAC.Element eleInCluster1 in cluster1)
            {
                foreach (HAC.Element eleInCluster2 in cluster2)
                {
                    float distance = metric.GetDistance(eleInCluster1, eleInCluster2);
                    //some approximation is used here to accelerate speed
                    if (distance < 0.3)
                    {
                        return distance;
                    }
                    if (distance < leastDistance)
                    {
                        leastDistance = distance;
                    }
                }
            }

            return leastDistance;
        }
    }
}
